#!/usr/bin/env python3
# encoding: utf-8

"""
@version: 1.0
@author: 周永波
@file: es.py
@time: 2020/8/25 11:37
"""
from elasticsearch import Elasticsearch

from demoApp.util import appUtils

esdb:Elasticsearch

class ELS:

    def __init__(self, property={}) -> None:
        esProperty = appUtils.dict_get(property, ['es'])
        self.hosts = appUtils.dict_get(esProperty, ['hosts'],default=('127.0.0.1:9200'))
        self.sniff_on_start = appUtils.dict_get(esProperty, ['sniff_on_start'], default=True)
        self.sniff_on_connection_fail = appUtils.dict_get(esProperty, ['sniff_on_connection_fail'], default=True)
        self.sniff_timeout = appUtils.dict_get(esProperty, ['sniff_timeout'], default=60)
        global esdb
        esdb = Elasticsearch(
            self.hosts,  # 连接集群，以列表的形式存放节点的ip地址
            sniff_on_start=self.sniff_on_start,  # 连接前测试
            sniff_on_connection_fail=self.sniff_on_connection_fail,  # 节点无响应时刷新节点
            sniff_timeout=self.sniff_timeout  # 设置超时时间
        )



